package com.lingmengnj.utils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import com.lingmengnj.anotation.LMField;
import com.lingmengnj.models.Company;
import com.lingmengnj.models.Department;


public class GenTools {
	private final String DIC="C:/AGenProj/";
	//private final String DAOPACKAGE="com.test.dao";
	private final String PROJECTPACKAGE="com.newtouch"; 
	private final String DAOPACKAGE="com.newtouch.dao";
	private final String MODELPACKAGE="com.newtouch.model";//pojo package
	private final String SERVICEPACKAGE="com.newtouch.service";
	private final String COMMONPACKAGE="com.newtouch.common";
	private final String ACTIONPACKAGE="com.test.action";
	private final String DBPRE="NT_";
	
	private void createFileDic(String path){
		//boolean flag=false;
		File file=new File(path);
		if(!file.exists())    
		{    
		       file.mkdirs();  
		}
		//return flag;
	}
	
   public static void main(String[] args) {
	   GenTools tools=new GenTools();
	   tools.createFileDic(tools.DIC);
	   
	   ///Users/lingmeng/Workspaces/MyEclipse10/FinanceAnalyze/src/main/java/com/fa/util/Test.java
	   try {
		   
		 /*  tools.genDataBaseCreateSql(new Company());  
		   tools.genDataBaseMapSql(new Company());
		   tools.genDaolayer(new Company());*/
		   tools.genServer(new Company());
		 
	   } catch (IOException e) {
		   e.printStackTrace();
	   }
		/*
		final String DOMAINPACKAGE="";
		final String XMLPRENAME="";
		
		//���sqlmap������SEQ_SysUser xml��d\daoĿ¼�� ��,����sql���ڿ���̨�� 
		tools.genDataBaseSql(new SysAdministrative(),"com.lingmengnj.dao.model.","RIMS_");*/
		//dao��󲿷ַ����Ѿ������baseDAO �ӿ��ļ���impl�ļ�
		//tools.genDaolayer(new SysAdministrative(), "com.lingmengnj.dao.logic");
		//service�� �ӿ��ļ���impl�ļ� 
		//tools.genServer(new SysAdministrative(), "com.lingmengnj.service", "");
		//action��
		/*package com.lingmengnj.action;
        public class DriverAction extends BaseAction {*/
		
		//jspҳ��
		
		//���application �ļ� struts.xml�ļ�     struts�ļ���Ҫ�ֶ�����sql-map-config��
		
	}
	private void genJsp(Object obj,String packagepre,String projectname){
		
	}
	private void genAddOrUpdateJsp(Object obj,String packagepre,String projectname){
		//customersaddorupdateview.jsp
	}
    private void genListJsp(Object obj,String packagepre,String projectname){
		//customersList.jsp
	}
    private void genSpringMVC(){
    	
    }
	/**由类生成建表语句
	 * @param obj 类实例
	 * @throws IOException 
	 */
    private void genDataBaseCreateSql(Object obj) throws IOException{
    	Class<? extends Object> objc=obj.getClass();
    	
    	System.out.println(objc.getSimpleName());
    	
    	Type genType = objc.getGenericSuperclass();// 得到泛型父类 
    	Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); 
        Type pkType=params[0];
    	/*for(Type c:params){
    		System.out.println(c);
    		pkType=c;
    	}*/
    	
    	Field[] fie2=objc.getSuperclass().getDeclaredFields();
    	
		Field[] fie1=objc.getDeclaredFields();
		Field[] fie=new Field[fie2.length+fie1.length];
		System.arraycopy(fie2,0,fie,0,fie2.length); 
		System.arraycopy(fie1,0,fie,fie2.length,fie1.length);
		String uttabledatabasename=DBPRE+objc.getSimpleName();
		
		String pks="";
		
		
		String createtablesql="create table ";//sql
		createtablesql=createtablesql+uttabledatabasename+"(";
		
		for(int i=0;i<fie.length;i++)
		{
			int STRFIELD=255;//"��ʹ��ע���ʱ��ΪĬ���ֶγ���"
			String NUMBERACC="";
			boolean useTimeStamp=false;
			boolean isPKey=false;
			
			
			String type=fie[i].getType().getName();
			
			
            for(Annotation ano : fie[i].getAnnotations()){
            	LMField lmf=(LMField)ano;
            	STRFIELD=lmf.fleidLength();
            	NUMBERACC=lmf.numberAccuracy();
            	useTimeStamp=lmf.useTimeStamp();
            	isPKey=lmf.isPKey();
            	if(isPKey){
            		pks=pks+fie[i].getName()+",";
            	}
            }
			String end=",";
			if(i==fie.length-1){
				end=" ";
			}
			
			Type generaltype=fie[i].getGenericType();
			//System.out.println(generaltype.toString());
			if ("T".equals(generaltype.toString()))
			{
				type=pkType.toString();
			//	System.out.println(type);
			} 
			else{
				type=generaltype.toString();
			}
			
			if (type.equals("class java.lang.String"))
			{
				createtablesql=createtablesql+fie[i].getName()+"  VARCHAR2("+STRFIELD+")"+end;
			}
			else if (type.equals("class java.util.Date"))
			{
				createtablesql=createtablesql+fie[i].getName()+(useTimeStamp?" timestamp":"  DATE")+end;
			}
			else if (type.equals("class java.sql.Timestamp"))
			{
				createtablesql=createtablesql+fie[i].getName()+"  timestamp"+end;
			}
			else if (type.equals("class java.lang.Long"))
			{
				createtablesql=createtablesql+fie[i].getName()+"  NUMBER"+NUMBERACC+""+end;
			}
			else if (type.equals("class java.lang.Integer"))
			{
				createtablesql=createtablesql+fie[i].getName()+"  NUMBER"+NUMBERACC+""+end;
			}
			else if (type.equals("class java.lang.Double"))
			{
				createtablesql=createtablesql+fie[i].getName()+"  NUMBER"+NUMBERACC+""+end;
			}
			else if (type.equals("class java.lang.Boolean"))
			{
				createtablesql=createtablesql+fie[i].getName()+"  Char(1)"+end;
			}
			else if (type.equals("class java.lang.Character"))
			{
				createtablesql=createtablesql+fie[i].getName()+"  Char(1)"+end;
			}
		}
		//System.out.println(pks);
		if("".equals(pks)){
			System.out.println(createtablesql+");");
		}
		else{
		String pkstart="CONSTRAINT PK_"+objc.getSimpleName()+"  primary key ("+pks.substring(0,pks.lastIndexOf(","))+")";
		
		createtablesql=createtablesql+(!"".equals(pks)?","+pkstart:"")+");";
		System.out.println(createtablesql);
		}
    }
    
    /**生成 sqlmap
	 * @param obj 对象
	 * @throws IOException 
	 */
	private void genDataBaseMapSql(Object obj) throws IOException{

		Class<? extends Object> objc=obj.getClass();
	    Field[] fie2=objc.getSuperclass().getDeclaredFields();
		
		boolean usemid=true;
		if(fie2.length==0)
			 usemid=false;
		
		Field[] fie1=objc.getDeclaredFields();
		Field[] fie=new Field[fie2.length+fie1.length];
		System.arraycopy(fie2,0,fie,0,fie2.length); 
		System.arraycopy(fie1,0,fie,fie2.length,fie1.length);
		String utsimplename=objc.getSimpleName();
		String uttabledatabasename=DBPRE+objc.getSimpleName();
		String resultmapresult="";//map
		String selectwheresql="";//selectWhere
		String insertsql="";//insert
		String updatesql="";//update
		String deletesql="";//delete
		String selectsql="";//sql1
		String selectsql2="";//sql2
		String selectcountsql="";
		String filepathname=DIC+uttabledatabasename+"_SqlMap.xml";
		
		//���sqlmap
		/**
		 * <?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<!DOCTYPE sqlMap PUBLIC \"-//ibatis.apache.org//DTD SQL Map 2.0//EN\" \"http://ibatis.apache.org/dtd/sql-map-2.dtd\" >
<sqlMap namespace="glkjict" >
  <resultMap id="GlkjIctResult" class="com.jshx.glkj.dao.ibatis.model.GlkjIct" >
    <result column="ID" property="id"  />
    <result column="ICT_DWBH" property="ictDwbh" jdbcType="VARCHAR" />
		 * */
		String sqlmappre="<?xml version=\"1.0\" encoding=\"UTF-8\" ?><!DOCTYPE sqlMap PUBLIC \"-//ibatis.apache.org//DTD SQL Map 2.0//EN\" \"http://ibatis.apache.org/dtd/sql-map-2.dtd\" >\r\n";
	    String sqlmap="<sqlMap namespace=\""+utsimplename+"\" >\r\n";
	    String resultmap="<resultMap id=\""+utsimplename+"ResultMap\" class=\""+MODELPACKAGE+"."+utsimplename+"\" >\r\n";
	    
	    resultmapresult=sqlmappre+sqlmap+resultmap;
	    System.out.println("length:"+fie.length);
	    for(int j=0;j<fie.length;j++)
		{
	    	System.out.println("fie name:"+fie[j].getName());
	    	resultmapresult=resultmapresult+"<result column=\""+fie[j].getName().toUpperCase()+"\" property=\""+fie[j].getName()+"\"  />\r\n";
		}
	    resultmapresult=resultmapresult+"</resultMap>";
	 
	    //�������
	    /**
	     * <sql id="glkjict.ictselectwhere" ><dynamic>
      <isNotEmpty prepend="and" property="ictYdallinput" >
        ICT_YDALLINUPT = #ictYdallinput:VARCHAR#
      </isNotEmpty>
	     * */
	    selectwheresql="<sql id=\""+utsimplename+".selectwhere\"><dynamic prepend=\"where\" >\r\n";
	    for(int j=0;j<fie.length;j++)
		{
	    	selectwheresql=selectwheresql+"<isNotEmpty prepend=\"and\" property=\""+fie[j].getName()+"\" >\r\n";
	    	
	    	
	    	String type=fie[j].getType().getName();
	    	if (type.equals("java.lang.String"))
			{
	    		selectwheresql=selectwheresql+" "+fie[j].getName().toUpperCase()+"=#"+fie[j].getName()+":VARCHAR#\r\n";
			}
			else if (type.equals("java.util.Date"))
			{
				selectwheresql=selectwheresql+" "+fie[j].getName().toUpperCase()+"=#"+fie[j].getName()+":DATE#\r\n";
			}
			else if (type.equals("java.lang.Long"))
			{
				selectwheresql=selectwheresql+" "+fie[j].getName().toUpperCase()+"=#"+fie[j].getName()+"#\r\n";
			}
			else if (type.equals("java.lang.Integer"))
			{
				selectwheresql=selectwheresql+" "+fie[j].getName().toUpperCase()+"=#"+fie[j].getName()+"#\r\n";
			}
			else if (type.equals("java.lang.Double"))
			{
				selectwheresql=selectwheresql+" "+fie[j].getName().toUpperCase()+"=#"+fie[j].getName()+":DECIMAL#\r\n";
			}
	    	selectwheresql=selectwheresql+" </isNotEmpty>";
		}
	    selectwheresql=selectwheresql+" </dynamic></sql>";
	    //System.out.println(selectwheresql);
	    
	    
	    
	    //���insert
	    /**
	     *  <insert id="glkjict.insert" parameterClass="com.jshx.glkj.dao.ibatis.model.GlkjIct" >
  <selectKey resultClass="java.lang.Integer" type="pre" keyProperty="id">
  		select SEQ_GLKJ_ICT.nextval as value from dual
  	</selectKey>
    insert into GLKJ_ICT (ID, ICT_DWBH, ICT_DWMC, ICT_XMBH, ICT_XMMC, ICT_KHMC, ICT_XMJSFS,
      ICT_XMJL, ICT_KHJL, ICT_QYZT, ICT_HTQX, ICT_XMLX, ICT_QDSJ, ICT_KGSJ, ICT_WGSJ, ICT_CYSJ,
      ICT_ZYSJ, ICT_HTJBR, ICT_XMZJE, ICT_HTTK,ICT_QFYY,ICT_SCFLAG,ICT_KHSX,ICT_YDALLINUPT)
    values (#id#, #ictDwbh:VARCHAR#, #ictDwmc:VARCHAR#, #ictXmbh:VARCHAR#,
      #ictXmmc:VARCHAR#, #ictKhmc:VARCHAR#, #ictXmjsfs:VARCHAR#, #ictXmjl:VARCHAR#,
      #ictKhjl:VARCHAR#, #ictQyzt:VARCHAR#, #ictHtqx:DECIMAL#, #ictXmlx:VARCHAR#, #ictQdsj:DATE#,
      #ictKgsj:DATE#, #ictWgsj:DATE#, #ictCysj:DATE#, #ictZysj:DATE#, #ictHtjbr:VARCHAR#,
      #ictXmzje:DECIMAL#, #ictHttk:VARCHAR#, #ictQfyy:VARCHAR#,0,#ictKhsx:VARCHAR#,0)
  </insert>
	     * */
	    insertsql="<insert id=\""+utsimplename+".insert\" parameterClass=\""+MODELPACKAGE+"."+utsimplename+"\" >\r\n"+
	    "<selectKey resultClass=\"java.lang.Long\" type=\"pre\" keyProperty=\""+(usemid==true?"id":fie[0].getName())+"\">\r\n"+
	    "select SEQ_"+utsimplename.toUpperCase()+".nextval as value from dual</selectKey>\r\n insert into "+uttabledatabasename.toUpperCase()+" (";
	    for(int j=0;j<fie.length;j++)
		{
	    	String end=",";
			if(j==fie.length-1){
				end=" ";
			}
	    	insertsql=insertsql+fie[j].getName().toUpperCase()+end;
		}
	    insertsql=insertsql+") values (";
	    for(int j=0;j<fie.length;j++)
		{
	    	String end=",";
			if(j==fie.length-1){
				end=" ";
			}
	    	insertsql=insertsql+"#"+fie[j].getName()+"#"+end;
		}
	    insertsql=insertsql+")\r\n</insert>";
	    //System.out.println(insertsql);
	    
	    //���updatesql
	    /**
	     *  
  <update id="SysUser.update"
		parameterClass="com.lingmengnj.dao.model.SysUser">
		update vms_sysuser
		<dynamic prepend="set">
			<isNotNull prepend="," property="accountname">
				ACCOUNTNAME = #accountname#
			</isNotNull>
			<isNotNull prepend="," property="username">
				USERNAME = #username#
			</isNotNull>
			<isNotNull prepend="," property="password">
				PASSWORD = #password#
			</isNotNull>
			<isNotNull prepend="," property="email">
				EMAIL = #email#
			</isNotNull>
			<isNotNull prepend="," property="phone">
				PHONE = #phone#
			</isNotNull>
			<isNotNull prepend="," property="locked">
				LOCKED = #locked#
			</isNotNull>
		</dynamic>
		  where userid=#userid#
	</update>
	     * */
	    updatesql="<update id=\""+utsimplename+".update\"  parameterClass=\""+MODELPACKAGE+"."+utsimplename+
	    "\">\r\n update "+uttabledatabasename+" \r\n <dynamic prepend=\"set\" >";
	    for(int j=0;j<fie.length;j++)
		{
	    	if(j==0) 
	    		continue;
	    	else;
	    	updatesql=updatesql+"<isNotNull prepend=\",\" property=\""+fie[j].getName()+"\" > "+fie[j].getName().toUpperCase()+" = #"+fie[j].getName()+"#</isNotNull>\r\n";
		}
	    updatesql=updatesql+"</dynamic>";
	    
	    updatesql=updatesql+" where "+fie[0].getName()+" = #"+fie[0].getName()+"#\r\n";
	    
	    updatesql=updatesql+"</update>";
	    //System.out.println(updatesql);
	    
	    //delete
	    /**
	     * 
	     *  <delete id="icthxfk.delete" parameterClass="java.lang.String" >
    delete from GLKJ_ICTQRFK
    where ID = #id#
  </delete>
	     * */
	    deletesql="<delete id=\""+utsimplename+".delete\" parameterClass=\"java.lang.Long\" >\r\n delete from "+uttabledatabasename+" where "+(usemid==true?"ID":fie[0].getName().toUpperCase())+" = #"+(usemid==true?"id":fie[0].getName())+"#</delete>";
	    /**
	    <select id="SysUser.count"
			resultClass="java.lang.Long" parameterClass="mapBean">
			select count(*) from SysUser
			<include refid="SysUser.selectwhere" />
		</select>
	    */
	    selectcountsql="<select id=\""+utsimplename+".count\" resultClass=\"java.lang.Integer\" parameterClass=\"mapBean\" >\r\n " +
	    		"select count(*) from  "+uttabledatabasename+"\r\n<include refid=\""+utsimplename+".selectwhere\" />\r\n</select>";

	    	
	    //select
	    /**
	     * <select id="icthxfk.selectpage" resultMap="GlkjIcthxfkResult" parameterClass="mapBean" >
     <include refid="paginationStart" />
    select ID, ICT_ID, ICT_LZRQ, ICT_LZLX, ICT_QRJE, ICT_FYLB, ICT_GYSMC  
    from GLKJ_ICTQRFK
     <include refid="icthxfk.selectwhere" />
     <include refid="paginationEnd" />
  </select>
	     * */
	    selectsql="<select id=\""+utsimplename+".selectpage\" resultMap=\""+utsimplename+"ResultMap\"  parameterClass=\"mapBean\" >\r\n <include refid=\"paginationStart\" />\r\n select ";
	    for(int j=0;j<fie.length;j++)
		{
	    	String end=",";
			if(j==fie.length-1){
				end=" ";
			}
			selectsql=selectsql+fie[j].getName()+end;
		}
	    selectsql=selectsql+"  from "+uttabledatabasename+"\r\n <include refid=\""+utsimplename+".selectwhere\" />\r\n  <include refid=\"paginationEnd\" /> \r\n</select>";
	   // System.out.println(selectsql);
	
	    
	    
	    

	 //select2
    /**
     * <select id="icthxfk.select" resultMap="GlkjIcthxfkResult" parameterClass="mapBean" >

select ID, ICT_ID, ICT_LZRQ, ICT_LZLX, ICT_QRJE, ICT_FYLB, ICT_GYSMC  
from GLKJ_ICTQRFK
 <include refid="icthxfk.selectwhere" />

</select>
     * */
	 selectsql2="<select id=\""+utsimplename+".select\" resultMap=\""+utsimplename+"ResultMap\">\r\n  select ";
	    for(int j=0;j<fie.length;j++)
		{
	    	String end=",";
			if(j==fie.length-1){
				end=" ";
			}
			selectsql2=selectsql2+fie[j].getName()+end;
		}
	    selectsql2=selectsql2+"  from "+uttabledatabasename+"\r\n <include refid=\""+utsimplename+".selectwhere\" />\r\n  </select>";
	    //System.out.println(selectsql2);
	    
	    this.writeFile(filepathname, resultmapresult+"\r\n"+selectwheresql+"\r\n"+insertsql+"\r\n"+updatesql+"\r\n"+deletesql+"\r\n"+selectcountsql+"\r\n"+selectsql+"\r\n"+selectsql2+"\r\n"+"</sqlMap>");
	   // return resultmapresult+selectwheresql+insertsql+updatesql+deletesql+selectsql+selectsql2+"</sqlMap></xml>";
	}
	
	private void writeFile(String FilePathName, String content) throws IOException {
		   FileWriter fw=new FileWriter(FilePathName);
		   fw.write(content,0,content.length());
		   fw.flush();
		   fw.close();
    }
	
	private void genServer(Object obj) throws IOException{
		File f=new File(DIC+"service/");
		if(null!=f&&!f.exists())
		{
			f.mkdirs();
		}
		File f1=new File(DIC+"service/impl/");
		if(null!=f&&!f1.exists())
		{
			f1.mkdirs();
		}
		
		
		Class<? extends Object> objc=obj.getClass();
		String name=objc.getSimpleName();
		System.out.println(name+"-------getSimpleName");
		
		//package com.lingmengnj.service.impl;
		String writeString="package "+SERVICEPACKAGE+".impl;\r\n";
		
		
		writeString=writeString+"import java.util.List;\r\n";
		writeString=writeString+"import "+COMMONPACKAGE+".Page;\r\n";
		writeString=writeString+"import "+MODELPACKAGE+"."+name+";\r\n";
		writeString=writeString+"import "+SERVICEPACKAGE+"."+name+"Service;\r\n";
		writeString=writeString+"import "+DAOPACKAGE+"."+name+"Dao;\r\n";
		writeString=writeString+"import "+SERVICEPACKAGE+".base.impl.BaseServiceImpl;\r\n";
		writeString=writeString+"import org.springframework.beans.factory.annotation.Autowired;\r\n";
		writeString=writeString+"import org.springframework.stereotype.Service;\r\n";
		//import com.newtouch.service.base.BaseService;
		writeString=writeString+"@Service \r\n";
		writeString=writeString+"public class "+name+"ServiceImpl extends BaseServiceImpl  implements "+name+"Service{\r\n";
		
		writeString=writeString+"@Autowired \r\n";
		writeString=writeString+"private "+name+"Dao "+name.toLowerCase()+"dao;\r\n";  
		/*
		 * public DriverDao getDriverdao() {
		return driverdao;
	}

	public void setDriverdao(DriverDao driverdao) {
		this.driverdao = driverdao;
	}
	
		 * */
		writeString=writeString+"public "+name+"Dao get"+name+"dao(){\r\n";
		writeString=writeString+"return  "+name.toLowerCase()+"dao;\r\n}\r\n";
		
		writeString=writeString+"public void set"+name+"dao("+name+"Dao "+name.toLowerCase()+"dao){\r\n";
		writeString=writeString+"this."+name.toLowerCase()+"dao="+name.toLowerCase()+"dao;\r\n}\r\n";
		
		/*
		 * public void addVanBasicInfo(VanBasicInfo vanBasicInfo) {
		 vanbasicinfodao.insertModelObject(vanBasicInfo);
	}
       * */
		writeString=writeString+"public void add"+name+"("+name+" "+name.toLowerCase()+") {\r\n";
		writeString=writeString+name.toLowerCase()+"dao.insertModelObject("+name.toLowerCase()+");\r\n";
		writeString=writeString+"}\r\n";
		/*
		 * public Long deleteVanBasicInfo(String id) {
		return vanbasicinfodao.deleteModelObject(new Long(id));
	}

	*/
		writeString=writeString+"public Integer delete"+name+"(String id) {\r\n";
		writeString=writeString+"return "+name.toLowerCase()+"dao.deleteModelObject(new Long(id));\r\n";
		writeString=writeString+"}\r\n";
		/*
		 * public Long editVanBasicInfo(VanBasicInfo vanBasicInfo) {
		return vanbasicinfodao.updateModelObject(vanBasicInfo);
	}
		 * */
		//writeString=writeString+"public Long edit"+name+"(String id) {\r\n";
		writeString=writeString+"public Integer edit"+name+"("+name+" "+name.toLowerCase()+") {\r\n";
		writeString=writeString+"return "+name.toLowerCase()+"dao.updateModelObject("+name.toLowerCase()+");\r\n";
		writeString=writeString+"}\r\n";
		/*
		 * public VanBasicInfo findVanBasicInfoById(String id) {
		return vanbasicinfodao.getModelObject(new Long(id));
	}

	public List<VanBasicInfo> findVanBasicInfos(Page page) {
		return vanbasicinfodao.selectModelObjectListPage(page);
	}   **/
		writeString=writeString+"public "+name+" find"+name+"ById(String id) {\r\n";
		writeString=writeString+"return "+name.toLowerCase()+"dao.getModelObject(new Long(id));\r\n";
		writeString=writeString+"}\r\n";
		
		writeString=writeString+"public List<"+name+"> find"+name+"s(Page page) {\r\n";
		writeString=writeString+"return "+name.toLowerCase()+"dao.selectModelObjectListPage(page);\r\n";
		writeString=writeString+"}\r\n";
		
		writeString=writeString+"}";
		this.writeFile(DIC+"service/impl/"+name+"ServiceImpl.java",writeString);
		
		
		String writeString1="package "+SERVICEPACKAGE+";\r\n";
		writeString1=writeString1+"import java.util.List;\r\n";
		writeString1=writeString1+"import "+COMMONPACKAGE+".Page;\r\n";
		writeString1=writeString1+"import "+MODELPACKAGE+"."+name+";\r\n";
		writeString1=writeString1+"import "+SERVICEPACKAGE+".base.BaseService;\r\n";
		writeString1=writeString1+"public interface "+name+"Service  extends BaseService{\r\n";
		
		writeString1=writeString1+"public List<"+name+"> find"+name+"s(Page page);\r\n";
		writeString1=writeString1+"public "+name+" find"+name+"ById(String id);\r\n";
		writeString1=writeString1+"public Integer edit"+name+"("+name+" "+name.toLowerCase()+");\r\n";
		writeString1=writeString1+"public Integer delete"+name+"(String id);\r\n";
		writeString1=writeString1+"public void add"+name+"("+name+" "+name.toLowerCase()+");\r\n}\r\n";
		this.writeFile(DIC+"service/"+name+"Service.java",writeString1);
	
	}
	
	
	private void genDaolayer(Object obj) throws IOException{
		/*
		 * package com.lingmengnj.dao.logic.impl;
           import com.lingmengnj.dao.base.impl.BaseDaoImpl;
           import com.lingmengnj.dao.logic.UserDao;
           public class UserDaoImpl extends BaseDaoImpl<User,Long> implements UserDao {
           }
		 * */
		File f=new File(DIC+"dao/");
		if(null!=f&&!f.exists())
		{
			f.mkdirs();
		}
		File f1=new File(DIC+"dao/impl/");
		if(null!=f&&!f1.exists())
		{
			f1.mkdirs();
		}
		
		Class<? extends Object> objc=obj.getClass();
		String name=objc.getSimpleName();
		//"com.lingmengnj.dao.logic"-->com.finance.dao
		String writeString="package "+DAOPACKAGE+".impl;\r\n";
		writeString=writeString+"import "+DAOPACKAGE+".base.impl.BaseDaoImpl;\r\n";
		writeString=writeString+"import org.springframework.stereotype.Repository;\r\n";
		writeString=writeString+"import "+DAOPACKAGE+"."+name+"Dao;\r\n";
		//import com.lingmengnj.dao.model.SysModuleButtons;
		writeString=writeString+"import "+MODELPACKAGE+"."+name+";\r\n";
		writeString=writeString+"@Repository\r\n";
		writeString=writeString+"public class "+name+"DaoImpl extends BaseDaoImpl<"+name+",Long> implements "+name+"Dao{\r\n";
		writeString=writeString+"public "+name+"DaoImpl(){\r\n";
		writeString=writeString+"this.setSqlmapNamespace(\""+name+"\");\r\n";
		writeString=writeString+"}\r\n";
		writeString=writeString+"}";
		this.writeFile(DIC+"dao/impl/"+name+"DaoImpl.java",writeString);
		
       /**
        * package com.lingmengnj.dao.logic;
import java.util.List;
import java.util.Map;
import com.lingmengnj.common.Page;
import com.lingmengnj.dao.base.BaseDao;
import com.lingmengnj.dao.model.SysUser;

public interface SysUserDao extends BaseDao{
	public SysUser getSysUserById(Integer id);
	public List<SysUser> getSysUserList(Map<String,String> paraMap);
	public List<SysUser> getSysUserListAsPage(Page page);
	public Integer updateSysUser(SysUser sysuser);
	public SysUser insertSysUser(SysUser sysuser);
	public Integer deleteSysUserById(Integer id);
	public Integer deleteSysUserLogicById(Integer id);
}
        * */ 
		String writeString1="package "+DAOPACKAGE+";\r\n import java.util.List;\r\n import java.util.Map;\r\n " +
				"import "+PROJECTPACKAGE+".common.Page;";
		writeString1=writeString1+"import "+DAOPACKAGE+".base.BaseDao;\r\n";
		writeString1=writeString1+"import "+MODELPACKAGE+"."+name+";\r\n";
		//extends BaseDaoImpl<SysRole,Integer>
		writeString1=writeString1+"public interface "+name+"Dao extends BaseDao<"+name+",Long>{\r\n";
		/*writeString1=writeString1+"public "+name+" get"+name+"ById(Integer id);\r\n";
		writeString1=writeString1+"public List<"+name+"> get"+name+"List(Map<String,String> paraMap);\r\n";
		writeString1=writeString1+"public List<"+name+"> get"+name+"ListAsPage(Page page);\r\n";
		writeString1=writeString1+"public Integer update"+name+"("+name+" "+name.toLowerCase()+");";
		writeString1=writeString1+"public "+name+" insert"+name+"("+name+" "+name.toLowerCase()+");";
		writeString1=writeString1+"public Integer delete"+name+"ById(Integer id);";
		writeString1=writeString1+"public Integer delete"+name+"LogicById(Integer id);";
		*/
		writeString1=writeString1+"}";
		
		
		this.writeFile(DIC+"dao/"+name+"Dao.java",writeString1);
	}

}
	
	
	


